package com.woniu.houtai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.woniu.houtai.entity.Business;
import com.woniu.houtai.entity.Shop;
import com.woniu.houtai.mapper.ShopMapper;
import com.woniu.houtai.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author firstGroup
 * @since 2023-02-22 09:45:58
 */
@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements ShopService {

    @Autowired
    ShopMapper shopMapper;

    @Override
    public Integer insert(String name, String detail, String imgSrc, Integer businessId) {

        Shop shop=new Shop();
        shop.setName(name);
        shop.setDetail(detail);
        shop.setImgSrc(imgSrc);
        shop.setBusinessId(businessId);
        return shopMapper.insert(shop);

    }

    @Override
    public Integer update(Integer id, String name, String detail, String imgSrc, Integer businessId) {
        QueryWrapper<Shop> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("id",id);
        Shop shop = shopMapper.selectOne(queryWrapper);
        shop.setName(name);
        shop.setDetail(detail);
        shop.setImgSrc(imgSrc);
        shop.setBusinessId(businessId);
        return shopMapper.updateById(shop);
    }

    @Override
    public Shop selectById(Integer id) {
        return shopMapper.selectById(id);
    }

    @Override
    public Page<Shop> selectByBusinessId(Integer currentPage, Integer pageSize, Integer businessId) {
        Page<Shop> shopPage = new Page<>(currentPage,pageSize);

        QueryWrapper<Shop> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("business_id",businessId);

        return shopMapper.selectPage(shopPage,queryWrapper);
    }

    @Override
    public Shop selectByBusinessIdAndName(Integer businessId, String name) {
        QueryWrapper queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("business_id",businessId);
        queryWrapper.eq("name",name);
        Shop shop = shopMapper.selectOne(queryWrapper);
        return shop;

    }

    @Override
    public List<Shop> selectByOnlyBusinessId(int businessId) {
        QueryWrapper queryWrapper =  new QueryWrapper<>();
        queryWrapper.eq("business_id",businessId);
        List listShop = shopMapper.selectList(queryWrapper);

        return listShop;
    }
}
